package pl.puntin.punclient.messages;

import java.util.HashMap;


/**
 * Singleton z leniwa inicalizacja
 * @author kakus
 *
 */
public class IncomingMessageTypesMap
{
	private static HashMap<Byte, Class<? extends Message>> typesMap;
	
	private static void initMapTypes()
	{
		typesMap = new HashMap<Byte, Class<? extends Message>>();
		
		/**
		 * Rejestracja wiadmosci jakie moze odebrac klient !
		 */
		typesMap.put(MessageTypes.IMAGE_MESSAGE, ImageMessage.class);
		typesMap.put(MessageTypes.CHAT_MESSAGE, ChatMessage.class);
		typesMap.put(MessageTypes.S_LOGIN_OK, LoginOkMessage.class);
		typesMap.put(MessageTypes.S_LOGIN_FALSE, LoginFalseMessage.class);
		typesMap.put(MessageTypes.S_PUN_FOR_DRAWER, PunForDrawerMessage.class);
		typesMap.put(MessageTypes.S_ROOM_LIST, RoomListMessage.class);
		typesMap.put(MessageTypes.S_ADD_ROOM_OK, AddRoomOkMessage.class);
		typesMap.put(MessageTypes.S_ADD_ROOM_FALSE, AddRoomFalseMessage.class);
		typesMap.put(MessageTypes.S_JOIN_ROOM_OK, JoinRoomOkMessage.class);
		typesMap.put(MessageTypes.S_JOIN_ROOM_FALSE, NotJoinRoomMessage.class);
		typesMap.put(MessageTypes.S_START_NEW_GAME_OK, StartNewGameOkMessage.class);
		typesMap.put(MessageTypes.S_START_NEW_GAME_FALSE, NotStartNewGameMessage.class);
		typesMap.put(MessageTypes.S_PUN_FOR_DRAWER, PunForDrawerMessage.class);
		typesMap.put(MessageTypes.S_DRAWER_PASSED, DrawerPassesMassege.class);
		typesMap.put(MessageTypes.S_DRAWER_LOGOUT, DawerLeaveMessage.class);
		typesMap.put(MessageTypes.S_SOMEONE_GUESSED, SomeOneGuessedMessage.class);
		typesMap.put(MessageTypes.S_ROUND_TIMEOUT, RoundTimeoutMessage.class);
		typesMap.put(MessageTypes.S_PLAYER_LOGIN, NewPlayerLoginMessage.class);
		typesMap.put(MessageTypes.S_UPDATE_RANKING, UpdateRankingMessage.class);
		typesMap.put(MessageTypes.S_FOREVER_ALONE, ForeverAloneMessage.class);
		typesMap.put(MessageTypes.S_PLAYER_LOGOUT, PlayerLogoutMessage.class);
		typesMap.put(MessageTypes.S_END_OF_GAME_WINNER, YouAreWinnerMessage.class);
		typesMap.put(MessageTypes.S_END_OF_GAME, EndOfGameMessage.class);
		typesMap.put(MessageTypes.S_NEW_ROUND, NewRoundMessage.class);
		typesMap.put(MessageTypes.S_GAME_ALREADY_BEGINED, GameAlreadyBeginedMessage.class);
		
	}
	
	public static Class<? extends Message> getClass(final byte code)
	{
		if(typesMap == null)
			initMapTypes();
		
		return typesMap.get(code);
	}
}
